package com.codestudy.dao;

import com.codestudy.entity.Collection;
import com.codestudy.entity.Concern;
import com.codestudy.entity.Likes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (Goodorbad)表数据库访问层
 *
 * @author makejava
 * @since 2024-04-09 09:15:21
 */
@Mapper
public interface LikesDao {

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    Likes queryById(Integer id);

    /**
     * 收藏
     */
    List<Collection> queryByCondition(Likes likes);

    /**
     * 点赞
     */
    List<Likes> queryByLike(Likes likes);

    /**
     * 查询收藏表
     */
    List<Collection> CollectionQueryByCondition(Collection collection);

    /**
     * 统计总行数
     */
    int count(Likes likes);

    /**
     * 新增数据
     */
    int insert(Likes likes);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     */
    int insertBatch(@Param("entities") List<Likes> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Likes> entities);

    /**
     * 修改数据
     */
    int update(Likes likes);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 影响行数
     */
    int deleteById(Integer id);

    int CollectionInsert(Collection c);

    int CollectionUpdate(Collection c);

    //根据文章id，和点赞状态码，查询点赞表中有几条数据，有几条数据即表示有几个赞
    @Select("select count(*) from likes where note_id = #{noteId} and active = #{active}")
    int getLikes(@Param("noteId") Integer noteId, @Param("active") int active);

    //根据文章id，和收藏状态码，查询收藏表中有几条数据，有几条数据即表示有多少收藏数
    @Select("select count(*) from collection where note_id = #{noteId} and active = #{active}")
    int getCollections(@Param("noteId") Integer noteId, @Param("active") int active);

    List<Concern> selectConcern(Concern concern);

    void ConcernInsert(Concern c);

    void ConcernDelete(int bgzId);

    Integer getGzConcern(Integer currentId);

    Integer getBgzConcern(Integer bgzCount);

    List<Concern> queryByConcern(Concern concern);

    @Select("select count(*) from likes where note_id = #{noteId} and active = 1")
    int getUserLikes(@Param("noteId") Integer noteId);

    @Select("select * from collection where note_id = #{noteId} and user_id = #{uid}")
    Collection queryByarticleId(@Param("noteId") Integer noteId, @Param("uid") Integer uid);

    @Select("select * from concern where bgz_id = #{bgzid} and gz_id = #{uid}")
    Concern queryConcernByNoteId(@Param("bgzid") Integer bgzid, @Param("uid") Integer uid);

    @Select("select user_id from note where user_id=#{userId} and id=#{noteId};")
    Integer queryByNote(Likes likesList);
}

